<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_content
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');

?>

<div>
	<h1>Home</h1>
	
	<ul>
		<?php foreach ($this->items as $category): ?>
		<?php if ($category->articles): ?>
		<li>
			<span class="item-title"><a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($category->id));?>">
				<?php echo $this->escape($category->title); ?></a>
			</span>
			
			<?php if ($category->articles): ?>
			<?php 
			
			
			//get first article 
			$firstArticle = $category->articles[0];
			
			$firstArticleImage = json_decode($firstArticle->images);
			
			//set slug
			$firstArticle->slug = $firstArticle->alias ? ($firstArticle->id . ':' . $firstArticle->alias) : $firstArticle->id;
			?>
			
			<div>
				<span class="list-title">
					<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($firstArticle->slug, $firstArticle->catid)); ?>">
						<?php echo $this->escape($firstArticle->title); ?>
					</a>
				</span>
				
				<?php if ($firstArticleImage->image_intro): ?>
				<img src="<?php echo $firstArticleImage->image_intro; ?>" />
				<?php endif; ?>
				
				<?php echo JHtml::_('string.truncate', strip_tags($firstArticle->introtext), 100); ?>
			</div>
			
			
			<ul>
				<?php foreach ($category->articles as $key => $article): ?>
				<?php 
						if ($key == 0) continue; 
						
						$article->slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
				?>
			
				<li>
					<span class="list-title">
						<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); ?>">
							<?php echo $this->escape($article->title); ?>
						</a>
					</span>
				</li>
			
				<?php endforeach; ?>
			</ul>
			<?php endif; ?>
		</li>
		<?php endif; ?>
		<?php endforeach; ?>
	</ul>
		
</div>